package com.example.apexapp.activity;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import com.example.apexapp.MyBroadcastReceiver;

import okhttp3.internal.Util;

public class BroadcastReceiver extends MyBroadcastReceiver {
    private static final String TAG = "BroadcastReceiver";
    private int mBatteryLevel;
    @Override
    public void onReceive(Context context, Intent intent){
        Log.d(TAG," -------- Receiver--------");
        Log.d(TAG,"Action:"+intent.getAction());
        Log.d(TAG,"URI"+intent.toUri(Intent.URI_INTENT_SCHEME));

        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){
            NetworkInfo info = ((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
            if (info != null&&info.isAvailable()){
                if ((info.getType() ==ConnectivityManager.TYPE_WIFI)){
                    Log.d(TAG,"使用WIFI");
                }
                else if (info.getType() == ConnectivityManager.TYPE_MOBILE){
                    String MobileType = Util.getMobileType(info);
                    Log.d(TAG,"正在使用"+mobileType +"移动网络");
                }
            }
            else {
                Log.d(TAG,"网络关闭");
            }
        }
        if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())){
            Log.d(TAG,"打开");
        }else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())){
            Log.d(TAG,"关闭");
        }
    }

}
